package com.stephen.redisdemo.thread;

import java.util.concurrent.TimeUnit;

public class InterruptedThreadDemo {

    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread("t1"){
            @Override
            public void run() {
                while (true) {
                    try {
                        TimeUnit.SECONDS.sleep(1);
                    } catch (InterruptedException e) {
                        System.out.println("stop...");
                        break;
                    }
                    System.out.println("t1 running");
                }
            }
        };

        t1.start();
        System.out.println("main running...");
        TimeUnit.SECONDS.sleep(2);
        // interrupt()方法是中断线程,设置标记为true
        t1.interrupt();
        // t1.isInterrupted()是查询线程状态,不会改变线程标记
        System.out.println("isInterrupted(): " + t1.isInterrupted());
        // 会
        // System.out.println("interrupted(): " + t1.interrupted());

        System.out.println("isInterrupted(): " + t1.isInterrupted());

    }

}
